namespace SPDeploy.Library.Processing.Library
{
    using System;
    using Helpers;
    using Interfaces;
    using Action=SPDeploy.Data.Action;

    public abstract class ProcessorBase<TData, TReturn> : IDeploymentTargetProcessor<TData, TReturn>
    {
        #region IDeploymentTargetProcessor<TData,TReturn> Members

        public ILogWriter LogWriter { get; set; }
        public abstract string Name { get; }

        public virtual bool CanProcess(Type t)
        {
            return t == typeof (TData) || t.IsSubclassOf(typeof (TData));
        }

        public abstract TReturn Install(ProcessorContext ctx, TData config);
        public abstract TReturn Uninstall(ProcessorContext ctx, TData config);
        public abstract TReturn Update(ProcessorContext ctx, TData oldConfig, TData newConfig);

        #endregion

        #region Methods: protected

        protected static string Describe(ProcessorModes mode, Action action)
        {
            return Language.ResourceManager.GetString(mode + action.ToString());
        }

        protected void Log(LogSeverity severity, string format, params object[] args)
        {
            if (LogWriter != null)
            {
                LogWriter.Write(severity, Name, format, args);
            }
        }

        #endregion
    }
}